use eframe::egui::IconData;
use eframe::{egui, NativeOptions};
use srsc_behavior_tree::app::BehaviorTreeApp;
use srsc_behavior_tree::config;
use std::sync::Arc;

fn main() {
    let native_options = build_options();
    eframe::run_native(
        config::APP_NAME,
        native_options,
        Box::new(|cc| Ok(Box::new(BehaviorTreeApp::new(cc)))),
    ).expect("panic!");
}

fn build_options() -> NativeOptions {
    let viewport = egui::ViewportBuilder::default()
        // 窗口视图大小
        .with_inner_size([1334.0, 750.0])
        // 软件icon
        .with_icon(get_icon_data());
    
    NativeOptions {
        viewport,
        // 打开默认居中
        centered: true,
        ..Default::default()
    }
}

fn get_icon_data() -> Arc<IconData> {
    let icon_data = include_bytes!("../resources/icon.png");
    let image = image::load_from_memory_with_format(icon_data, image::ImageFormat::Png).unwrap();
    let rgba_data = image.into_rgba8();
    let width = rgba_data.width();
    let height = rgba_data.height();
    let rgba = rgba_data.into_raw();
    Arc::<IconData>::new(IconData {
        rgba,
        width,
        height,
    })
}
